package cn.com.bluemoon.daps.system.service.impl;

import cn.com.bluemoon.daps.system.entity.DapSystemInfo;
import cn.com.bluemoon.daps.system.service.BizLineDeletePredicate;
import cn.com.bluemoon.daps.system.service.DapSystemInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 判断系统是否引用改业务线
 *
 * @author Jarod.Kong
 */
@Service
@Slf4j
public class SystemModuleBizLineDeletePredicate implements BizLineDeletePredicate {
    @Resource
    private DapSystemInfoService systemInfoService;

    @Override
    public Result<Integer> predicate(Integer bizLineId) {
        checkPredicate(bizLineId);
        List<DapSystemInfo> infos = systemInfoService.relatedBizLineId(bizLineId);
        if (!infos.isEmpty()) {
            return Result.<Integer>builder().canDelete(false).key(bizLineId).message("系统管理-系统配置已引用，不可删除").build();
        }
        return Result.<Integer>builder().canDelete(true).key(bizLineId).build();
    }
}
